import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import Element, { Message } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Element)
Vue.prototype.$message = Message

import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;

import VueQuillEditor from 'vue-quill-editor'

import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)

// axios自带的工具不需要安装npm依赖
import qs from 'qs'
// 将qs挂载到全局window上
window.qs = qs;

import axios from 'axios'
Vue.prototype.$axios = axios //前后端分离组件
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://39.102.76.217:8100/'  //关键代码

Vue.config.productionTip = false

import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
import 'videojs-contrib-hls' //单是 RTMP 的话不需要第三方库，如果是 HLS 的话需要引入videojs-contrib-hls，看具体情况而定。
Vue.use(VideoPlayer);

import { vueBaberrage } from 'vue-baberrage'
Vue.use(vueBaberrage);

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

router.beforeEach((to, from, next) => {
  //获取用户登录成功后储存的登录标志
  let getFlag = localStorage.getItem("Flag");
  //如果登录标志存在且为isLogin，即用户已登录
  if (getFlag === "isLogin") {

    //设置vuex登录状态为已登录
    store.state.isLogin = true
    next()

    //如果已登录，还想想进入登录注册界面，则定向回首页
    if (!to.meta.isLogin) {
      //iViewUi友好提示
      iView.Message.error('请先退出登录')
      next({
        path: '/home'
      })
    }

    //如果登录标志不存在，即未登录
  } else {

    //用户想进入需要登录的页面，则定向回登录界面
    if (to.meta.isLogin) {
      next({
        path: '/login',
      })
      //iViewUi友好提示
      iView.Message.info('请先登录')
      //用户进入无需登录的界面，则跳转继续
    } else {
      next()
    }

  }

});

router.afterEach(route => {
  window.scroll(0, 0);
});
